package com.atguigu.gmall.item.all.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
public class ItemController {
    @Autowired
    private ItemFeignClient itemFeignClient;

    //编写控制器
    @RequestMapping ("{skuId}.html")
    public String getItem(@PathVariable Long skuId, Model model){
        //获取数据 调用远程Feign
        Result<Map> result = itemFeignClient.getItem(skuId);
        //获得dataMap
        Map dataMap = result.getData();
        //存储数据
        model.addAllAttributes(dataMap);
        //返回的视图名称
        return "item/index";
    }
}
